package com.shawn;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisPoolDemo {

	private static volatile JedisPool pool;

	private JedisPoolDemo(){

	}

	public static JedisPool getJedisPoolInstance(){
		if(null == pool){
			synchronized (JedisPoolDemo.class) {
				if(null == pool){
					JedisPoolConfig config = new JedisPoolConfig();
					config.setMaxIdle(5);
					config.setMaxTotal(5);
					config.setTestOnBorrow(true);
					config.setMinIdle(0);
					config.setMaxWaitMillis(1000*100);
					pool = new JedisPool(config ,"192.168.1.103",6379,1800,"Gepoint");
				}
			}
		}
		return pool;
	}

	public static void main(String[] args) {
		JedisPool jedisPoolInstance = JedisPoolDemo.getJedisPoolInstance();
		Jedis resource = jedisPoolInstance.getResource();
		System.out.println(resource.ping());
	}

}
